package org.springcloud.plugin.test.rest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Author yanggld
 * @Date 2020/1/16-16:40
 * @Description
 */
@RestController
@ConditionalOnProperty(name = "spring.application.name", havingValue = "test-service-b")
public class BRestImpl {
	private static final Logger LOG = LoggerFactory.getLogger(BRestImpl.class);

	@Autowired
	private RestTemplate restTemplate;

	@Value("${server.port}")
	private String port;

	@GetMapping("/rest")
	public String rest(){
		return "restB:"+port;
	}

	@GetMapping("/restC")
	public String restC(){
		String url = "http://test-service-c/rest";
		ResponseEntity<String> entity = restTemplate.getForEntity(url, String.class, "");
		String body = entity.getBody();
		return body;
	}
}

